//
//  LayoutCellTableAndList.m
//  ebook
//
//  Created by 吴超飞 on 2017/3/16.
//  Copyright © 2017年 Moton. All rights reserved.
//

#import "LayoutCellTableAndList.h"
#import "LayoutCellTable.h"
#import "LayoutCellList.h"

@interface LayoutCellTableAndList()

@property (nonatomic, retain) LayoutCellTable *topTable;
@property (nonatomic, retain) LayoutCellList *bottomList;

@end

@implementation LayoutCellTableAndList

- (void)drawRect:(CGRect)rect {
    
    [self addSubview:self.topTable];
    [self addSubview:self.bottomList];
}

-(LayoutCellTable *)topTable{

    if (!_topTable) {
        _topTable = [[LayoutCellTable alloc]initWithFrame:CGRectMake(0, 0, MTScreenW, [LayoutCellTable oneRowHeight])];
    }
    return _topTable;
}

-(LayoutCellList *)bottomList{
    
    if (!_bottomList) {
        _bottomList = [[LayoutCellList alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.topTable.frame), MTScreenW, 100)];
        _bottomList.isNoHead = YES;
    }
    return _bottomList;
}

-(void)reloadData{
    
    NSInteger len = isIpad?6:4;
    if (self.dataArray.count>len) {
      
        _topTable.dataArray = [self.dataArray subarrayWithRange:NSMakeRange(0, len)];
        [_topTable reloadData];
        
        _bottomList.isNoHead = YES;
        _bottomList.dataArray = [self.dataArray subarrayWithRange:NSMakeRange(len, self.dataArray.count-len)];
        _bottomList.frame = CGRectMake(0, CGRectGetMaxY(self.topTable.frame), MTScreenW, kLayoutCellListItemHeight*(self.dataArray.count-len));
        [_bottomList reloadData];
    }
}

+(float)viewHeight:(LayoutType *)layoutType{
    
    return [LayoutCellTable oneRowHeight] + kLayoutCellListItemHeight*(layoutType.rows-1);
}

@end
